#include <QDebug>

#include "test_webclient.hpp"
#include "libsocialbox/web_client.hpp"

void TestWebClient::initTestCase()
{
    wc = new WebClient(WebClient::Synchronous);
}

void TestWebClient::cleanupTestCase()
{
    delete wc;
}

void TestWebClient::testGet()
{
    int status;
    QBuffer *output = new QBuffer();
    //output->open(QBuffer::WriteOnly);

    status = wc->get("http://www.google.com/search?q=socialbox", output);
    QVERIFY(output->data() != "");
    QVERIFY(status == 200);

    delete output;
}

void TestWebClient::testPost()
{
    QStringList args;
    QBuffer *output = new QBuffer();
    int status;
    //output->open(QBuffer::WriteOnly);

    args = QStringList();
    status = wc->post("http://www.javasonics.com/listenup/php_test/test_post.php", args, output);
    QVERIFY(output->data() != "");
    QVERIFY(status == 200);

    delete output;
}

void TestWebClient::testHostNotFound()
{
    QBuffer *output = new QBuffer();
    int status;

    //output->open(QBuffer::WriteOnly);
    status = wc->get("www.ahostthatisunknownfromdnsbecauseitdoesnotexist.com/handle_file_upload.php", output);
    QVERIFY(status == 203);

    delete output;
}

void TestWebClient::testPageNotFound()
{
    QBuffer *output = new QBuffer();
    int status;

    //output->open(QBuffer::WriteOnly);
    status = wc->get("www.javasonics.com/handle_file_upload.php", output);
    QVERIFY(status == 203);

    delete output;
}


